﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wf5.Engine.Common;
using Wf5.Engine.Utility;

using FCDB.Repository;
using FCDB.Entity;

namespace Wf5.Engine.Business
{
    /// <summary>
    /// 流程定义管理类
    /// </summary>
    public class ProcessManager
    {
        #region 属性、构造函数
        private WfProcessRepository _processRepository;
        private WfProcessRepository ProcessRepository
        {
            get
            {
                if (_processRepository == null)
                {
                    _processRepository = new WfProcessRepository();
                }
                return _processRepository;
            }
        }

        public ProcessManager()
        {
        }
        #endregion

        #region 获取流程数据
        public WfProcess GetById(Guid processGUID)
        { 
            return ProcessRepository.GetById(processGUID);
        }

        public WfProcess GetByName(string processName)
        {
            return  ProcessRepository.GetByName(processName);
            
        }
        #endregion

        #region 新增、更新和删除流程数据
        public void Insert(WfProcess entity)
        { 
            try
            {
                
                ProcessRepository.Add(entity ); 
            }
            catch (System.Exception)
            { 
                throw;
            }
          
        }

        public void Update(WfProcess entity)
        {
             
            try
            {
                ProcessRepository.Update(entity ); 
            }
            catch (System.Exception)
            {
                
                throw;
            }
          
        }

        public void Delete(Guid processGUID)
        {
             
            try
            {
                var entity = GetById(processGUID);
                ProcessRepository.Delete(entity);
               
            }
            catch (System.Exception)
            {
                
                throw;
            }
           
        }
        #endregion 
    }
}
